package org.budo.netty.servlet.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lmw
 */
public class UrlUtil {
    public static Map<String, String[]> queryStringToMap(String queryString) {
        Map<String, String[]> map = new HashMap<String, String[]>();
        if (null == queryString || queryString.isEmpty()) {
            return map;
        }

        String[] pairs = queryString.split("&");
        for (String pair : pairs) {
            String[] kv = pair.split("=");
            if (kv.length == 2) {
                map.put(kv[0], new String[] { kv[1] });
                continue;
            }

            if (kv.length == 1) {
                map.put(kv[0], new String[] { "" });
                continue;
            }
        }

        return map;
    }
}